package com.guoranhao.tool.utils;


/**
 * Description:
 * All Rights Reserved.
 *
 * @version 1.0  2017/12/25 17:53  by  马双亮（masl@cloud-young.com）创建
 */
public class FileUrlUtils {

    /**
     * 图片前缀
     */
    public static String prefix = "dev";

    /**
     * 根据环境配置获取前缀
     *
     * @param env
     * @return
     */
    public static String getUrlByEnv(int env) {
        if (env == 1) {
            return "http://cloud-young.oss-cn-beijing.aliyuncs.com/";
        }
        return "http://cloud-young-test.oss-cn-beijing.aliyuncs.com/";
    }

    /**
     * 替换前缀为空串
     *
     * @param str
     * @return
     */
    public static String replacePrefix(String str) {
        if (null != str && str.trim().length() > 0) {
            str = str.replaceAll(FileUrlUtils.prefix, "");
        }
        return str;
    }

    /**
     * 替换前缀为空串
     *
     * @param str
     * @return
     */
    public static String replacePrefix(String str, String inputPrefix) {
        if (null != str && str.trim().length() > 0) {
            str = str.replaceAll(inputPrefix, "");
        }
        return str;
    }

    /**
     * 增加前缀
     *
     * @param str
     * @return
     */
    public static String addPrefix(String str) {
        if (null != str && str.trim().length() > 0) {
            str = FileUrlUtils.prefix + str;
        }
        return str;
    }

    /**
     * 增加前缀
     *
     * @param str
     * @return
     */
    public static String addPrefix(String str, String inputPrefix) {
        if (null != str && str.trim().length() > 0) {
            str = inputPrefix + str;
        }
        return str;
    }


}
